package com.likl.service.impl;

import com.likl.service.MsgService;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * ClassName:springboot_study
 * Description:
 *
 * @Create: 2024/7/12 11:38
 * @author: likl
 * @e-mail: likl1102@foxmail.com
 * @QQ: 2514927731
 */
@Service
public class MsgServiceImpl implements MsgService {

    private HashMap<String, String> cache = new HashMap<>();

    @Override
    public String get(String phone) {
        String code = phone.substring(phone.length() - 6);
        cache.put(phone, code);
        return code;
    }

    @Override
    public boolean check(String phone, String code) {
        String cacheCode = cache.get(phone);
        if (cacheCode == null) {
            return false;
        }
        return cacheCode.equals(code);
    }
}
